import rclpy
import espeakng
from rclpy.node import Node
from autopatol_interfaces.srv import SpeechText

class Speaker(Node):
    def __init__(self,node_name):
        super().__init__(node_name)
        self.srv = self.create_service(SpeechText, 'speech_text', self.speech_text_callback)
        self.speaker = espeakng.Speaker()
        self.speaker.voice = 'zh'

    def speech_text_callback(self, request, response):
        self.get_logger().info(f'收到语音请求:{request.text}')
        self.speaker.say(request.text)
        self.speaker.wait()
        response.result = True
        return response

def main(args=None):
    rclpy.init(args=args)
    node = Speaker('speaker')
    rclpy.spin(node)
    rclpy.shutdown()